#!/usr/bin/env python
#coding: utf8


__author__ = 'Исаков Владислав'
__project_name__ = 'isakov-selenium-python'
__date__ = '07.04.14'


def add_film(self, driver):
    # click | css=img[alt="Add movie"] |
    driver.find_element_by_css_selector("img[alt=\"Add movie\"]").click()
    # assertTitle |  My movie collection - php4dvd v2.0  |
    self.assertEqual("My movie collection - php4dvd v2.0", driver.title[1:-1])
    # type | id=imdbsearch | test_1
    driver.find_element_by_id("imdbsearch").clear()
    driver.find_element_by_id("imdbsearch").send_keys("test_1")
    # type | name=imdbid | 1
    driver.find_element_by_name("imdbid").clear()
    driver.find_element_by_name("imdbid").send_keys("1")
    # type | name=name | Первый тестовый фильм
    driver.find_element_by_name("name").clear()
    name_film1 = u"Первый тестовый фильм"
    driver.find_element_by_name("name").send_keys(name_film1)
    # type | name=year | 1999
    year = "1999"
    driver.find_element_by_name("year").clear()
    driver.find_element_by_name("year").send_keys(year)
    # type | name=duration | 89
    driver.find_element_by_name("duration").clear()
    driver.find_element_by_name("duration").send_keys("89")
    # type | id=cover | C:\Users\Testerfff\YandexDisk\Картинки\Bug\bug (1).jpg
    # driver.find_element_by_id("cover").clear()
    driver.find_element_by_id("cover").send_keys(u"C:\\Users\\Testerfff\\YandexDisk\\Картинки\\Bug\\bug (1).jpg")
    # type | name=trailer | http:\\test.com
    driver.find_element_by_name("trailer").clear()
    driver.find_element_by_name("trailer").send_keys("http://test.com")
    # type | id=text_languages_0 | eng, rus
    driver.find_element_by_id("text_languages_0").clear()
    driver.find_element_by_id("text_languages_0").send_keys("eng, rus")
    # type | name=country | US
    driver.find_element_by_name("country").clear()
    driver.find_element_by_name("country").send_keys("US")
    # click | id=submit |
    driver.find_element_by_id("submit").click()
    # assertTitle |  My movie collection - php4dvd v2.0  |
    self.assertEqual("My movie collection - php4dvd v2.0", driver.title[1:-1])

    # проверяем название фильма в карточке, чтобы оно соответствовало "Название" + "Год" введенные вначале
    name_film1_add = driver.find_element_by_xpath(".//*[@id='movie']/div[2]/h2")
    self.assertEqual(name_film1 + " (" + year + ")", name_film1_add.text)